﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WpfApplication5.Models;

namespace WpfApplication5.ViewModels
{
    public class FunctionCategoryViewModel:TreeViewItemViewModel
    {
        private FunctionCategory _category;
        private SQLiteDatabase _db;
        public FunctionCategoryViewModel(FunctionCategory category, TreeViewItemViewModel parentCategory,SQLiteDatabase db)
            : base(parentCategory, true)
        {
            this._category = category;
            this._db = db;
        }
        public FunctionCategory Category
        {
            get { return _category; }
        }
        protected override void LoadChildren()
        {
            var ltChildren = _db.ParentLoad(_category.Id);
            if (ltChildren != null && ltChildren.Count > 0)
            {
                foreach (var cate in ltChildren)
                {
                    base.Children.Add(new FunctionCategoryViewModel(cate, this, _db));
                }
                return;
            }
            var ltInfo = _db.GetFunctionInfo(_category.Id);
            if (ltInfo != null)
            {
                foreach (var info in ltInfo)
                {
                    base.Children.Add(new FunctionInfoViewModel(info, this,_db));
                }
            }
        }
    }
}
